<template>
	<view class="">
		<view class="top">
			<view class="dizhi" v-for="(item,index) in addressList" :key="index">
				<view class="" style="display: flex;">
					<view class="name">
						{{item.name}}
					</view>
					<view class="sjh">
						{{item.phone}}
					</view>
					<view class="" v-if="item.is_default == 0">
						
						
					</view>
					
					<view class="" v-if="item.is_default == 1">
						
						<view class="redyangshi" v-if="item.is_default == 1">
							默认
						</view>
					</view>
					
					
					
					
					
					<view class="redyangshi">
						{{item.d_address}}
					</view>
					
				</view>
				<view class="xxdz">
					{{item.detail}} {{item.floor}}
				</view>
				
				<view class="caozuo">
					<view class="" style="display: flex;align-items: center;">
						<view @click="checkMoren(item)" v-if="item.is_default == 0" class="" style="width: 40rpx;height: 40rpx;border: 3rpx solid #ccc;text-align: center;line-height: 40rpx;">
							
						</view>
						<view v-if="item.is_default == 1" class="" style="width: 40rpx;height: 40rpx;border: 3rpx solid #ccc;text-align: center;line-height: 40rpx;">
							√
						</view>
						
						
						<view class="" style="padding: 10rpx;">
							默认
						</view>
					</view>
					<view class="" style="display: flex;">
						<view class="shanchu" @click="shanchuaddress(item)">
							删除
						</view>
						<view class="xiugai" @click="xiugai(item)">
							修改
						</view>
					</view>
				</view>
			</view>
			
			
			
		</view>
		
		<view class="addAddress" @click="goWriteAddress">
			新增地址
		</view>
		
	</view>
</template>

<script>
	export default {
		data(){
			return{
				addressList:[],
				
			}
		},
		onShow() {
			this.getMyAddress()
		},
		methods:{
			getMyAddress(){
				this.$req('GET',this.$api.getMyAddress,{
					school_id:uni.getStorageSync('addressId'),
					user_id:uni.getStorageSync('userId')
				}).then(res =>{
					console.log(res,'查看地址列表')
					this.addressList = res.data.list.data
					console.log(this.addressList,'this.addressListaddressList')
					
				}) 
			},
			// 删除地址
			delAddress(){
				this.$req('POST',this.$api.delAddress,{}).then(res =>{
					console.log(res,'查看有没有删除这个地址')
				})
			},
			goWriteAddress(){
				uni.navigateTo({
					url: `/writeaddress-pkg/writeaddress/writeaddress?type=${0}`
				})
			},
			shanchuaddress(item){
				console.log(item,'查看点击删除')
				this.$req('POST',this.$api.delAddress,{
					address_id:item.id
				}).then(res =>{
					this.getMyAddress()
				})
			},
			xiugai(item){
				
				uni.navigateTo({
					url: `/writeaddress-pkg/writeaddress/writeaddress?name=${item.name}&detail=${item.detail}&phone=${item.phone}&id=${item.id}&type=${1}`
				})
			},
			checkMoren(item){
				console.log(item,'查看点击默认')
				this.$req('POST',this.$api.adressXiu,{
					name:item.name,
					phone:item.phone,
					detail:item.xuanze,
					user_id:uni.getStorageSync('userId'),
					school_id:uni.getStorageSync('addressId'),
					floor:item.addDetail,
					is_default:1,
					id:item.id
					
				}).then(res =>{
					console.log(res,'查看默认')
					this.getMyAddress()
					
				})
				
				
				
			}
			
			
		}
	}
</script>

<style>
	page {
		background: #eee;
	}
	.top{
		width: 100%;
		height: 1000rpx;
		position: absolute;
		overflow-y: scroll;
	}
	
	.addAddress{
		width: 100%;
		background-color: rgba(238,66,53);
		color: #fff;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		position: relative;
		top: 1300rpx;
		left: 0;
	}
	
	.dizhi{
		width: 95%;
		background-color: #fff;
		margin: 20rpx auto;
		border-radius: 10rpx;
	}
	
	.redyangshi{
		font-size: 28rpx;
		border: 3rpx solid red; 
		color: red;
		padding: 5rpx;
		margin: 5rpx;
	}
	
	.redyangshis{
		font-size: 28rpx;
		border: 3rpx solid red; 
		color: red;
		padding: 5rpx;
		margin: 5rpx;
		display: none;
	}
	
	
	.name{
		font-weight: 900;
		padding: 10rpx;
	}
	
	.sjh{
		font-weight: 900;
		padding: 10rpx;
	}
	
	.xxdz{
		font-weight: 900;
		padding: 10rpx;
	}
	
	.caozuo{
		display: flex;
		justify-content: space-between;
		padding: 10rpx;
		
	}
	
	.shanchu{
		width: 120rpx;
		height: 50rpx;
		background-color: #ccc;
		text-align: center;
		line-height: 50rpx;
		border-radius: 30rpx;
		margin: 10rpx;
		
	}
	
	.xiugai{
		width: 120rpx;
		height: 50rpx;
		background-color: #ccc;
		text-align: center;
		line-height: 50rpx;
		border-radius: 30rpx;
		margin: 10rpx;
	}
	
</style>